<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Chronikles - Films</title>
<meta name="description" content="Chronikles portal">
<meta name="author" content="Scott n Jim">

<meta name="viewport" content="width=device-width">

<link rel="stylesheet" href="../assets/css/bootstrap.min.css">
<style>
body {
	padding-top: 40px;
	padding-bottom: 10px;
}
</style>
<link rel="stylesheet" href="../assets/css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="../assets/css/style.css">

</head>
<body>
	<%
		//Checking if a redirect from previous action
		String outputstyle = "style=\"display:none;\"";
		String outputtext = "";
		String stringParam = request.getParameter("r");
		int param = 99; // initialised to 99 so doesn't conflict with any error codes.
		if (stringParam != null) {
			param = Integer.parseInt(stringParam);
		}
		switch (param) {
		case 0:
			outputstyle = "class=\"alert alert-error\"";
			outputtext = "Something's totally fudged, plz let us kno xox";
			break;
		case 1:
			outputstyle = "class=\"alert alert-block\"";
			outputtext = "Film already exists.";
			break;
		case 2:
			outputstyle = "class=\"alert alert-success\"";
			outputtext = "Successfully added! =D";
			break;
		}
	%>
	<div class="navbar navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<a class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse"> <span class="icon-bar"></span> <span
					class="icon-bar"></span> <span class="icon-bar"></span>
				</a> <a class="brand" href="index.jsp">Chronikles</a>
				<div class="nav-collapse">
					<ul class="nav">
						<li><a href="index.jsp">Home</a></li>
						<li><a href="register.jsp">Register</a></li>
						<li class="active"><a href="films.jsp">Films</a></li>
					</ul>
				</div>
				<!--/.nav-collapse -->
			</div>
		</div>
	</div>
	<!-- Add Film Form -->
	<div class="span4">
		<div
			<%// get's style if has been set
			out.println(outputstyle);%>>
			<label> <%
 	//Prints message if has been set
 	if (outputtext != "") {
 		out.println(outputtext);
 	}
 %>
			</label>
		</div>
		<br />
		<form class="well" action="../AddFilmServlet" method="POST">
			<!-- Make dis Servlet -->
			<h3>Add Film</h3>
			<br /> <label>Film Name</label> <input type="text" name="filmName">
			<label>Description</label>
			<textarea rows="4" cols="20" maxlength="98" name="filmDesc"></textarea>
			<div class="controls">
				<label>Genre</label> <select name="filmGenre">
					<option value="Comedy">Comedy</option>
					<option value="Action">Action</option>
					<option value="Thriller">Thriller</option>
					<option value="Horror">Horror</option>
					<option value="Horror">Adventure</option>
					<option value="Horror">Animation</option>
					<option value="Drama">Drama</option>
					<option value="Crime">Crime</option>
					<option value="Sci-Fi">Sci-Fi</option>
					<option value="Western">Western</option>
					<option value="Other">Other</option>
				</select>
			</div>
			<button type="submit" class="btn">Submit</button>
		</form>
	</div>



	<!-- Form for searching films. Dropdown of genres & text search -->

	<div class="row">
		<div class="span8">
			<br />
			<form class="well" action="SearchFilmServlet.java">
			<h4>Search Films</h4>
				<!-- Make dis Servlet -->
				<input type="text" class="input-medium search-query"
					name="searchFilmText" value="Search"> <select
					name="searchFilmGenre">
					<option value="Comedy">Comedy</option>
					<option value="Action">Action</option>
					<option value="Thriller">Thriller</option>
					<option value="Horror">Horror</option>
					<option value="Horror">Adventure</option>
					<option value="Horror">Animation</option>
					<option value="Drama">Drama</option>
					<option value="Crime">Crime</option>
					<option value="Sci-Fi">Sci-Fi</option>
					<option value="Western">Western</option>
					<option value="Other">Other</option>
				</select>

				<button type="submit" class="btn">Search</button>

			</form>




		</div>
		<!-- Table of Films -->
		<div class=span8>
			<br />
			<table class="table table-striped table-bordered table-condensed">
				<tr>
					<th>Film</th>
					<th>Genre</th>
					<th>Description</th>
					<th>Date Added</th>
					<th>Added By</th>
					<th>Rating</th>
					<th>NumVotes</th>
					<th>Actions</th>
				</tr>

				<!-- Will be implemented as a c:foreach here once servlet, service & mySQl table completed -->
				<tr>
					<c:forEach var="film" items="${filmlist}">
						<tr>
							<td><c:out value="${film.name}" /></td>
							<td><c:out value="${film.genre}" /></td>
							<td><c:out value="${film.description}" /></td>
							<td><c:out value="${film.dateAdded}"/></td>
							<td><c:out value="${film.userWhoAdded}"/></td>
							<td><c:out value="${film.rating}" /></td>
							<td><c:out value="${film.numvotes}" /></td>
							<td><a
								href="..\AddRatingServlet?id=<c:out value = "${film.idFilm}"/>&name=<c:out value = "${film.name}"/>">Add
									a Rating</a></td>
						</tr>
					</c:forEach>
				</tr>
				<!-- End of the c:foreach -->
			</table>
		</div>
	</div>

</body>
</html>